package com.swind.fast.modules.app.halali.partner.controller;

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.common.constant.CommonConstant;
import com.swind.fast.modules.app.halali.partner.entity.HalaliUser;
import com.swind.fast.modules.app.halali.partner.entity.Restaurant;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantService;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantCategory;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantCategoryService;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantMeal;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealService;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantMealCategory;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealCategoryService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.swind.fast.common.system.base.controller.SwindController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
// import com.swind.fast.common.aspect.annotation.AutoLog;

import com.swind.fast.modules.system.entity.SysAnnouncement;
import com.swind.fast.modules.system.entity.SysAnnouncementSend;
import com.swind.fast.modules.system.service.ISysAnnouncementSendService;
import com.swind.fast.modules.system.service.ISysAnnouncementService;

import com.swind.fast.modules.app.halali.partner.vo.request.RestaurantVo;
import com.swind.fast.modules.app.halali.partner.vo.response.RestaurantInfoVo;
import com.swind.fast.modules.app.halali.partner.vo.common.FileUploadVo;
import org.springframework.http.MediaType;
import com.swind.fast.modules.app.halali.partner.component.HalaliUtils;
import io.swagger.annotations.ApiParam;
import com.swind.fast.modules.app.halali.partner.entity.BankAccount;
import com.swind.fast.modules.app.halali.partner.vo.request.BankAccountVo;

 /**
 * @Description: 餐厅
 * @Author: swind
 * @Date:   2022-01-20
 * @Version: V1.0
 */
@Api(tags="04.商户端-餐厅")
@RestController
@RequestMapping("/app/partner/restaurant")
@Slf4j
public class RestaurantController extends SwindController<Restaurant, IRestaurantService> {

	@Autowired
	private HalaliUtils halaliUtils;

	@ApiOperation(value="餐厅详情", notes="")
	@GetMapping(value = "/detail")
	public Result<RestaurantInfoVo> detailAction(@RequestParam(name="id", required=true) String id) {
		RestaurantInfoVo result = this.service.getDetailInfo(id);
		return Result.OK(result);
	}

	@ApiOperation(value="更新配置", notes="")
	@PostMapping(value = "/update")
	public Result<RestaurantInfoVo> updateAction(@RequestBody() RestaurantVo info) {
		RestaurantInfoVo result = this.service.updateInfo(info);
		return Result.OK(result);
	}

    @ApiOperation(value="更新银行", notes="")
    @PostMapping(value = "/update/bank")
    public Result<BankAccount> updateBankAction(@RequestBody() BankAccountVo info) {
        BankAccount result = this.service.updateBankInfo(info);
        return Result.OK(result);
    }

    // @ApiOperation(value="上传图片")
    // @PostMapping(value = "/update/image")
    // public Result<FileUploadVo> updatePic(
    //         @ApiParam(name ="file",type="MultipartFile",value="image.jpg",example="image.jpg",required=true)
    //         @RequestParam(name="file", required=true) MultipartFile file,
    //         @ApiParam(name ="imageType",type="Integer",value="图片类型,0-店铺图,1-Logo,2-清真证书,3-营业执照",example="1",required=false)
    //         @RequestParam(name="imageType", required=false) Integer imageType
    //         ) {
    //     String bizPath = "";
    //     if (oConvertUtils.isEmpty(imageType) || imageType == 0) {
    //         bizPath = "halali/restaurant/pic";
    //     } else if (imageType == 1) {
    //         bizPath = "halali/restaurant/logo";
    //     } else if (imageType == 2) {
    //         bizPath = "halali/restaurant/cert";
    //     } else if (imageType == 3) {
    //         bizPath = "halali/restaurant/license";
    //     }

    //     FileUploadVo fileVo = halaliUtils.uploadLocal(file, bizPath);

    //     RestaurantVo info = new RestaurantVo();
    //     if (oConvertUtils.isEmpty(imageType) || imageType == 0) {
    //         info.setPic(fileVo.getSavePath());
    //     } else if (imageType == 1) {
    //         info.setLogoUrl(fileVo.getSavePath());
    //     } else if (imageType == 2) {
    //         info.setHalaliCertImgUrl(fileVo.getSavePath());
    //     } else if (imageType == 3) {
    //         info.setLicenseImgUrl(fileVo.getSavePath());
    //     }

    //     this.service.updateInfo(info);
    //     return Result.OK(fileVo);
    // }

	@ApiOperation(value="上传图片", produces=MediaType.MULTIPART_FORM_DATA_VALUE)
    @PostMapping(value = "/update/image", headers="content-type=multipart/form-data")
    public Result<FileUploadVo> updatePic(
    		@ApiParam(name ="imageType",type="Integer",value="图片类型,0-店铺图,1-Logo,2-清真证书,3-营业执照",example="1",required=false)
    		@RequestParam(name="imageType", required=false) Integer imageType,
    		HttpServletRequest request, HttpServletResponse response) {
    	MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
        String bizPath = "";
        if (oConvertUtils.isEmpty(imageType) || imageType == 0) {
        	bizPath = "halali/restaurant/pic";
        } else if (imageType == 1) {
        	bizPath = "halali/restaurant/logo";
        } else if (imageType == 2) {
        	bizPath = "halali/restaurant/cert";
        } else if (imageType == 3) {
        	bizPath = "halali/restaurant/license";
        }
        FileUploadVo fileVo = halaliUtils.uploadLocal(file, bizPath);

        RestaurantVo info = new RestaurantVo();
        if (oConvertUtils.isEmpty(imageType) || imageType == 0) {
        	info.setPic(fileVo.getSavePath());
        } else if (imageType == 1) {
        	info.setLogoUrl(fileVo.getSavePath());
        } else if (imageType == 2) {
        	info.setHalaliCertImgUrl(fileVo.getSavePath());
        } else if (imageType == 3) {
        	info.setLicenseImgUrl(fileVo.getSavePath());
        }

        this.service.updateInfo(info);
        return Result.OK(fileVo);
    }
}
